﻿#region

using System.Linq.Expressions;
using System.Reflection;

#endregion

namespace SharpObservation
{
    /// <summary>
    ///   Extracts a property member from a lambda expression
    /// </summary>
    internal class PropertyPathExtractor : ExpressionVisitor
    {
        /// <summary>
        ///   The expression containing the member accessor
        /// </summary>
        public MemberExpression CurrentExpression { get; private set; }

        protected override Expression VisitMember(MemberExpression expression)
        {
            switch (expression.Member.MemberType)
            {
                case MemberTypes.Property:
                    if (CurrentExpression == null)
                        CurrentExpression = expression;
                    break;
            }

            return base.VisitMember(expression);
        }
    }


    /// <summary>
    ///   Extracts a property member from a lambda expression
    /// </summary>
    internal class MemberInfoExtractor : ExpressionVisitor
    {
        /// <summary>
        ///   The expression containing the member accessor
        /// </summary>
        public MemberInfo Info { get; private set; }

        protected override Expression VisitMember(MemberExpression expression)
        {
            switch (expression.Member.MemberType)
            {
                case MemberTypes.Method:
                    if (Info == null)
                    {
                        var member = (MemberExpression) expression;
                        Info = (member).Member as MethodInfo;
                    if (Info == null)
                    {
//                        member.Expression
                    }
                     }

                    break;
                    
            }

            return base.VisitMember(expression);
        }
    }
}